
Sub 例2936()
Dim grf As Chart
Dim scel As Range
'保存先パス
phn = ActiveWorkbook.Path
If phn = "" Then
MsgBox "このブックと同じフォルダ−へGIFを保存します" & Chr(10) _
& "パス未定の為ブックを1度保存してから実行して下さい"
Exit Sub
End If
'コピ−個所指定
msg = "GIFで保存するセル範囲を指定して下さい。" & Chr(10) _
& "(セル範囲をシ−トから指定して下さい)"
On Error Resume Next
Application.DisplayAlerts = False
Set scel = Application.InputBox(msg, "セル指定", Type:=8)
Application.DisplayAlerts = True
If TypeName(scel) = "Nothing" Then
MsgBox "セル範囲をシ−トから指定して下さい"
Exit Sub
End If
On Error GoTo 0
scel.Select
'画像コピ−
Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
ActiveSheet.Paste
ActiveSheet.Pictures.Select
pnam2 = Selection.Name
ActiveSheet.Shapes(pnam2).Select
hei = Selection.ShapeRange.Height
wid = Selection.ShapeRange.Width
'チャ−ト枠作成
Set grf = ActiveSheet.ChartObjects.Add(0, 0, wid + 8, hei + 8).Chart
grf.Paste
'gif保存
grf.Export phn & "\" & "Mygif.gif"
'仮作成の図形削除
grf.Parent.Delete
ActiveSheet.Shapes(pnam2).Select
Selection.Delete
Range("A1").Select
End Sub
Sub 参2921()
'最終セル
ActiveCell.SpecialCells(xlLastCell).Select
endr = ActiveCell.Row
endc = ActiveCell.Column
'罫線
Range(Cells(2, 1), Cells(endr, endc)).Select
Selection.Borders(xlEdgeLeft).Weight = xlThin
Selection.Borders(xlEdgeTop).Weight = xlThin
Selection.Borders(xlEdgeBottom).Weight = xlThin
Selection.Borders(xlEdgeRight).Weight = xlThin
Selection.Borders(xlInsideVertical).Weight = xlThin
Selection.Borders(xlInsideHorizontal).Weight = xlThin
Range("A2").Select
End Sub
Sub 参2922()
'罫線
Range(Cells(2, 1), Cells(endr, endc)).Select
Selection.Borders(xlEdgeLeft).Weight = xlThin
Selection.Borders(xlEdgeTop).Weight = xlThin
Selection.Borders(xlEdgeBottom).Weight = xlThin
Selection.Borders(xlEdgeRight).Weight = xlThin
Selection.Borders(xlInsideVertical).Weight = xlThin
If endr <> 2 Then
Selection.Borders(xlInsideHorizontal).Weight = xlThin
End If
Range("A2").Select
End Sub
Sub Macro1()
ActiveSheet.Shapes.AddTextEffect(msoTextEffect30, "VBA便利帳", "MS Pゴシック", 36#, _
msoFalse, msoFalse, 346.5, 112.5).Select
Selection.ShapeRange.TextEffect.ToggleVerticalText
Selection.ShapeRange.TextEffect.PresetShape = msoTextEffectShapeWave1
Selection.ShapeRange.IncrementRotation -4.15
pnam2 = Selection.Name
Range("C5").Select
ActiveSheet.Shapes(pnam2).Select
Selection.ShapeRange.Fill.Visible = msoTrue
Selection.ShapeRange.Fill.Solid
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 11
Selection.ShapeRange.Fill.Transparency = 0#
Selection.ShapeRange.Fill.OneColorGradient msoGradientFromCenter, 1, 0.38
Application.CommandBars("WordArt").Visible = False
End Sub
Sub 例2938()
Dim grf As Chart
'保存先パス
phn = ActiveWorkbook.Path
If phn = "" Then
MsgBox "このブックと同じフォルダ−へGIFを保存します" & Chr(10) _
& "パス未定の為ブックを1度保存してから実行して下さい"
Exit Sub
End If
'コピ−個所指定
On Error Resume Next
pnam2 = Selection.Name
If Err = 1004 Then
MsgBox "図を選んでから実行して下さい"
On Error GoTo 0
Exit Sub
End If
On Error GoTo 0
'画像コピ−
ActiveSheet.Shapes(pnam2).Select
hei = Selection.ShapeRange.Height
wid = Selection.ShapeRange.Width
Selection.Copy
'チャ−ト枠作成
Set grf = ActiveSheet.ChartObjects.Add(0, 0, wid + 8, hei + 8).Chart
grf.Paste
ggg1 = grf.Name
ggg2 = Mid(ggg1, InStr(1, ggg1, "グ", 1))
'枠線なし
ActiveSheet.ChartObjects(ggg2).Activate
ActiveChart.ChartArea.Select
Selection.Border.LineStyle = 0
'gif保存
grf.Export phn & "\" & "Mygif.gif"
'仮作成の図形削除
grf.Parent.Delete
Range("A1").Select
End Sub
Sub 例2939()
Cells(1, 1) = "Aaaaa Bbbbbb ア ルミCcccc Ddddカ セット eeムー ンR"
dat = Cells(1, 1)
ja = 1: jb = 0: daa = ""
Do
da1 = InStr(ja, dat, " ")
If da1 > 0 Then
data = Mid(dat, da1 - 1, 1)
If Hex(Asc(data)) > "8100" Then
jb = 1
daa = Left(dat, da1 - 1)
dab = Mid(dat, da1 + 1)
dat = daa & dab
ja = da1
Else
ja = da1 + 1
End If
Else
If jb = 1 Then
Exit Do
End If
End If
Loop Until da1 = 0
Cells(3, 1) = dat
End Sub
結果:Aaaaa Bbbbbb アルミCcccc DdddカセットeeムーンR
本例はブランクを全てチェックし、そのブランクが日本語の後ろの場合は
削除しました。日本語の判定として一応アスキ−コ−ドの"8100"以上としましたが
このマクロで問題がある場合は再度メ−ルを下さい。(なお上記例のように
"セット ee"が"セットee"のように全ての日本文字の後ろが詰まる欠点があります)。
Sub 例2940() Cells(1, 1) = "Aaaaa Bbbbbb ア ルミCcccc Ddddカ セット eeムー ンR" Cells(1, 1).Select ActiveCell.Replace " ", "" ActiveCell.Replace " ", "" End Sub 結果:AaaaaBbbbbbアルミCccccDdddカセットeeムーンR
Sub 参293()
msg = "ASCコ−ドを取得する文字を入力してください。"
moz = Application.InputBox(msg, "文字入力", "", Type:=2)
If moz = "" Then
Exit Sub
End If
msg1 = "文字「" & moz & "」のASCコ−ドは" & Chr$(10) & Chr$(10) _
& " →→ &H" & Hex(Asc(moz))
MsgBox msg1
End Sub
Sub 参294()
msg = "文字を取得するASCコ−ドを入力してください。" & Chr$(10) _
& "(入力したコ−ド番号は16進数として解釈)"
moz1 = Application.InputBox(msg, "文字入力", "", Type:=2)
If moz1 = "" Then
Exit Sub
End If
moz = "&H" & moz1
If IsNumeric(moz) = False Then
MsgBox "入力した文字は16進数になりません"
Exit Sub
End If
msg1 = "ASCコ−ド「" & moz & "」の文字は" & Chr$(10) & Chr$(10) _
& " →→→ " & Chr(moz)
MsgBox msg1
End Sub
Sub 例2941()
'保存先パス
phn = ActiveWorkbook.Path
If phn = "" Then
MsgBox "このブックと同じフォルダ−へ保存します" & Chr(10) _
& "パス未定の為ブックを1度保存してから実行して下さい"
Exit Sub
End If
'フォルダ−チェック
If Dir(phn & "\MyGIF" & "\*") = "" Then
On Error Resume Next
MkDir phn & "\MyGIF"
If Err = 75 Then
RmDir phn & "\MyGIF"
MkDir phn & "\MyGIF"
End If
On Error GoTo 0
End If
phn = phn & "\MyGIF"
’-----保存マクロは省略(29-36・29-38参照)----
End Sub
ファルダ−の有無チェックでファイル指定"\*"が無いとエラ−になります。
'画面サイズ拡大
Private Sub Workbook_Open()
If Application.DisplayFullScreen = False Then
Application.DisplayFullScreen = True
End If
End Sub
'画面サイズ戻す
Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
Application.DisplayFullScreen = False
End Sub
Const kw1 As Single = 1.2 '図形の拡大(横)
Const kh1 As Single = 1.3 '図形の拡大(縦)
Const kw2 As Single = 0.8 '図形の縮小(横)
Const kh2 As Single = 0.7 '図形の縮小(縦)
Dim kw As Single
Dim kh As Single
Dim km As Integer '拡大
Dim pnam2 As String '図形名
Dim scel As Object
Sub 拡大()
If ActiveSheet.Pictures.Count = 0 Then
km = 0
End If
kw = kw1
kh = kh1
セル指定
End Sub
Sub 縮小()
kw = kw2
kh = kh2
セル指定
End Sub
Sub セル指定()
If km = 0 Then
'コピ−個所指定
msg = "拡大したいセル範囲を指定して下さい。" & Chr(10) _
& "(セル範囲をシ−トから指定して下さい)"
On Error Resume Next
Application.DisplayAlerts = False
Set scel = Application.InputBox(msg, "セル指定", Type:=8)
Application.DisplayAlerts = True
If TypeName(scel) = "Nothing" Then
MsgBox "セル範囲をシ−トから指定して下さい"
Exit Sub
End If
On Error GoTo 0
scel.Select
Selection.Interior.ColorIndex = 35
'画像コピ−
Selection.CopyPicture Appearance:=xlScreen, Format:=xlPicture
Range("B2").Select
ActiveSheet.Paste
shc = ActiveSheet.Pictures.Count
ActiveSheet.Pictures(shc).Select
pnam2 = Selection.Name
ActiveSheet.Shapes(pnam2).Select
hei = Selection.ShapeRange.Height
wid = Selection.ShapeRange.Width
End If
表示
End Sub
Sub 表示()
'拡大表示
km = 1
ActiveSheet.Shapes(pnam2).Select
Selection.ShapeRange.ScaleWidth kw, msoFalse, msoScaleFromTopLeft
Selection.ShapeRange.ScaleHeight kh, msoFalse, msoScaleFromTopLeft
DoEvents
Range("A1").Select
End Sub
Sub 削除()
km = 0
shc = ActiveSheet.Pictures.Count
If shc > 0 Then
shc = ActiveSheet.Pictures.Count
ActiveSheet.Pictures(shc).Select
pnam2 = Selection.Name
ActiveSheet.Shapes(pnam2).Select
Selection.Delete
End If
End Sub
Private Sub Workbook_Open()
Application.OnKey "^{up}", "拡大"
Application.OnKey "^{down}", "縮小"
Application.OnKey "^{del}", "削除"
End Sub
Private Sub Workbook_Open()
Application.OnKey "{F10}", "拡大"
Application.OnKey "{F11}", "縮小"
Application.OnKey "{F12}", "削除"
End Sub
Dim col(100)
Dim scel As Object
Sub セル指定()
'コピ−個所指定
msg = "セル範囲を指定して下さい。"
On Error Resume Next
Application.DisplayAlerts = False
Set scel = Application.InputBox(msg, "セル指定", Type:=8)
Application.DisplayAlerts = True
If TypeName(scel) = "Nothing" Then
MsgBox "セル範囲をシ−トから指定して下さい"
Exit Sub
End If
On Error GoTo 0
scel.Select
色1
Range("A1").Select
End Sub
Sub 戻す()
scel.Select
色2
Range("A1").Select
End Sub
Sub 色1()
i = 1
For Each sel In Selection
If sel.Interior.ColorIndex = xlNone Then
col(i) = xlNone
sel.Interior.ColorIndex = 35
Else
col(i) = sel.Interior.ColorIndex
End If
i = i + 1
Next sel
End Sub
Sub 色2()
i = 1
For Each sel In Selection
sel.Interior.ColorIndex = col(i)
i = i + 1
Next sel
End Sub

(1) セル1個の場合
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Target.Address = Cells(2, 2) Then
Selection.Validation.IMEMode = xlIMEModeOn
End If
End Sub
(2)列を指定した場合
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
Dim retu As Variant
Set retu = Application.Intersect(Target, Range(Columns(2), Columns(3)))
If retu Is Nothing Then
Exit Sub
Else
With Selection.Validation
.Delete
.Add Type:=xlvalidatelnputonly
.IMEMode = xlIMEModeOn
End With
End If
End Sub

timck = Timer
For i = 1 To cen1
Range(Cells(4, 17), Cells(endr, 17)) _
.Replace What:=yaku(0, i), Replacement:=yaku(1, i), LookAt:=xlPart, _
SearchOrder:=xlByColumns, MatchCase:=True, MatchByte:=True
Next
MsgBox "マクロ処理時間(秒)⇒ " & Timer - timck
※ 上記の変数cen1・endr・配列yaku(*, *)は事前に代入してあります。
| True:大文字小文字を区別、False:区別しない | True:半角全角を区別、False:区別しない | 実行秒 | |
| 1 | MatchCase:=False | MatchByte:=False | 62.83 |
| 2 | MatchCase:=True | MatchByte:=False | 62.66 |
| 3 | MatchCase:=False | MatchByte:=True | 17.95 |
| 4 | MatchCaseの記述省略 | MatchByteの記述省略 | 18.01 |
| 5 | MatchCase:=True | MatchByte:=True | 9.01 |
| 6 |
Dim Myrang As Range Set Myrang = Range(Cells(4, 17), Cells(endr, 17)) Myrang _ .Replace What:=yaku(0, i), Replacement:=yaku(1, i), LookAt:=xlPart, _ SearchOrder:=xlByColumns, MatchCase:=True, MatchByte:=True |
8.83 | |
Sub 例2950()
'最終セル
ActiveCell.SpecialCells(xlLastCell).Select
endr = ActiveCell.Row
'
For j = 4 To endr
Cells(j, 2) = StrConv(Cells(j, 2), 8)
Cells(j, 17) = StrConv(Cells(j, 17), 4)
Next
End Sub
上記は、2列デ−タを半角に17列デ−タを全角に統一した例。